/**
 * Generali Solutions d'assurances - Tous droits réservés &copy; 2007 - 2010
 */
package fr.generali.accueilclient.resume.contrat.assembler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import fr.generali.accueilclient.resume.contrat.builder.DTOContrat2ResumeContratBuilder;
import fr.generali.accueilclient.resume.contrat.builder.IResumeContratBuilder;
import fr.generali.accueilclient.resume.contrat.builder.ResumeContratDirector;
import fr.generali.accueilclient.resume.contrat.om.IResumeContrat;
import fr.generali.refservcommuns.clients.resume.dto.v4.ctr.structurecontrat.DTOContrat;

/**
 * Transforme un {@link DTOContrat} en {@link IResumeContrat}
 * 
 * @author Guillaume Lancelin
 */
@Component("dtoContrat2ResumeContratConverter")
public class DTOContrat2ResumeContratConverter implements Converter<DTOContrat, IResumeContrat> {

    /**
     * LOGGER
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(DTOContrat2ResumeContratConverter.class);

    /**
     * {@inheritDoc}
     */
    public IResumeContrat convert(DTOContrat contrat) {
        LOGGER.debug("assemble");
        IResumeContrat resume = null;

        if (contrat != null) {

            IResumeContratBuilder resumeContratBuilder = new DTOContrat2ResumeContratBuilder(contrat);
            ResumeContratDirector resumeContratDirector = new ResumeContratDirector(resumeContratBuilder);

            resumeContratDirector.constructResumeContrat();
            resume = resumeContratDirector.getResumeContrat();
        }

        return resume;
    }
}
